﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageTardiness : Objective
    {
        public AverageTardiness()
            : base()
        {
        }
        public AverageTardiness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageTardinesss = 0;
            double totalTardiness = 0;

            int tardiness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {

                tardiness = Math.Max(0, order.EndDate - order.DueDate);
                totalTardiness = totalTardiness + tardiness;
            }

            averageTardinesss = totalTardiness / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageTardinesss);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderDueDateValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
        }


        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Tardiness";
                aboutInfo.Guid = new Guid("{0A85753B-54C9-4021-A059-4A007F38A9C8}");
                aboutInfo.Description = Resources.AverageTardinessDescription;
                return aboutInfo;
            }
        }

    }
}
